<template>
  <div>
    <base-header type="gradient-success" class="pb-6 pb-8 pt-5 pt-md-7"></base-header>
    <notifications></notifications>
    <div class="container-fluid mt--7">
      <div class="card shadow">
        <card type="frame">{{title}}</card>
        <div class="card-header border-0">
          <div>
            <div class="form-group row">
              <label class="col-md-2 col-form-label form-control-label">小队标题</label>
              <div class="col-md-10">
                <base-input v-model="model.teamname"></base-input>
              </div>
            </div>
            <div class="form-group row">
              <label
                for="example-search-input"
                class="col-md-2 col-form-label form-control-label"
              >小队简介</label>
              <div class="col-md-10">
                <textarea class="form-control" rows="3" v-model="model.teamdes"></textarea>
              </div>
            </div>

            <div class="form-group row">
              <label
                for="example-search-input"
                class="col-md-2 col-form-label form-control-label"
              >小队编号</label>
              <div class="col-md-10">
                <base-input v-model="model.teamno" disabled></base-input>
              </div>
            </div>
            <div class="form-group row">
              <label
                for="example-search-input"
                class="col-md-2 col-form-label form-control-label"
              >小队类型</label>
              <div class="col-md-10">
                <base-radio name="1" class="mb-3" v-model="model.type">公开</base-radio>
                <base-radio name="2" class="mb-3" v-model="model.type">私有</base-radio>
              </div>
            </div>
            <div class="form-group row">
              <label
                for="example-search-input"
                class="col-md-2 col-form-label form-control-label"
              >队长昵称</label>
              <div class="col-md-10">
                <base-input v-model="model.leadername" disabled></base-input>
              </div>
            </div>

            <div class="form-group row">
              <label for="example-email-input" class="col-md-2 col-form-label form-control-label">人数</label>
              <div class="col-md-10">
                <base-input type="text" v-model="model.currentmember" />
              </div>
            </div>
            <div class="form-group row">
              <label
                for="example-search-input"
                class="col-md-2 col-form-label form-control-label"
              >是否推荐</label>
              <div class="col-md-10">
                <base-radio name="1" class="mb-3" v-model="model.recommend">推荐</base-radio>
                <base-radio name="0" class="mb-3" v-model="model.recommend">不推荐</base-radio>
              </div>
            </div>

            <!-- <div class="form-group row" v-show="showSaveBtn">
              <label for="example-time-input" class="col-md-2 col-form-label form-control-label"></label>
              <div class="col-md-10">
                <base-button type="success" @click="saveAncient()">
                  <i class="ni ni-send"></i>提交
                </base-button>
              </div>
            </div>-->
            <div class="form-group row" v-show="showUpdateBtn">
              <label for="example-time-input" class="col-md-2 col-form-label form-control-label"></label>
              <div class="col-md-10">
                <base-button type="success" @click="update()">
                  <i class="ni ni-send"></i>更新
                </base-button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import validate from "~/config/utils/validate";
import {
  findLdTeamByIdApi,
  updateLdTeamByIdApi,
} from "~/config/api/ldteamservice";
export default {
  asyncData() {},
  head: {
    title: "小队记录",
  },
  name: "tables",
  data() {
    return {
      title: "",
      showSaveBtn: false,
      showUpdateBtn: false,
      model: {
        id: "",
        teamname: "",
        teamdes: "",
        teamno: "",
        type: "",
        leadername: "",
        currentmember: "",
        recommend: "",
      },
    };
  },
  created: function () {
    let pageaction = this.$route.query.action;
    if (pageaction == "save") {
      this.showSaveBtn = true;
    }
    if (pageaction == "edit") {
      this.title = "您正在编辑小队记录";
      this.showUpdateBtn = true;
      let id = this.$route.query.id;
      this.findById(id);
    }
  },
  mounted: function () {},
  methods: {
    async findById(id) {
      let params = {
        id: id,
      };
      await findLdTeamByIdApi(params).then((res) => {
        if (res.sucflag) {
          this.model.teamname = res.bean.teamname;
          this.model.teamdes = res.bean.teamdes;
          this.model.teamno = res.bean.teamno;
          this.model.type = res.bean.type;
          this.model.currentmember = res.bean.currentmember;
          this.model.recommend = res.bean.recommend;
          this.model.leadername = res.bean.leadername;
          this.model.id = res.bean.id;
        }
      });
    },
    async update() {
      let params = {
        id: this.model.id,
        teamname: this.model.teamname,
        teamdes: this.model.teamdes,
        currentmember: this.model.currentmember,
        recommend: this.model.recommend,
        type: this.model.type,
      };
      await updateLdTeamByIdApi(params).then((res) => {
        if (res.sucflag) {
          this.$router.push("/ldteam/ldteamslist");
        }
      });
    },
  },
  layout: "DashboardLayout",
};
</script>
<style></style>
